<?php
  include_once('../conn.php');

  // 接收由登录页面传来的数据
  $id = $_POST['id'];
  
  $username = $_POST['username'];
  $password1 = $_POST['password1'];
  $password2 = $_POST['password2'];
  $real_name = $_POST['real_name'];
  if(strlen($username) < 5) {
    alert('用户名不能小于5位', 'user_list.php');
    exit();
  }
  if($password1 != $password2) {
    alert('两次输入密码不相同，请重新输入', 'user_list.php');
    exit();
  }

  $sql = "update user set 
    username = '$username', 
    password = '$password1',
    real_name = '$real_name'
    where id = $id
    ";
  // echo $sql;
  $result = mysqli_query($conn, $sql);
  if($result) {
    alert('修改成功', 'user_list.php');
  } else {
    alert('修改失败', 'user_list.php');
  }

  mysqli_close($conn);
?>